﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DeviceManager.DataAccessLayer;
using DeviceManager.BusinessLogicLayer;
using DeviceManagementIT.DevicesManager.Unit;

namespace DeviceManagementIT.DevicesManager.DevicesManagement
{
    public partial class frmAddDevices : DevExpress.XtraEditors.XtraForm
    {
        DeviceBllOperation devicebll = new DeviceBllOperation();
        THIETBI device;
        
        public frmAddDevices()
        {
            InitializeComponent();
        }

        private void btnAddDVT_Click(object sender, EventArgs e)
        {
            frmAddUnit m_frmAddUnit = new frmAddUnit();
            m_frmAddUnit.Show();
        }

        private void frmAddDevices_Load(object sender, EventArgs e)
        {
            UnitDbOperation m_UnitDbOperation = new UnitDbOperation();
            cbbDVT.Properties.DataSource = m_UnitDbOperation.GetRecord(new DONVITINH());
            cbbDVT.Properties.DisplayMember = "DVTIT";
            cbbDVT.Properties.ValueMember = "DVTIT";

            CountryDbOperation m_CountryDbOperation = new CountryDbOperation();
            cbbNuocSX.Properties.DataSource = m_CountryDbOperation.GetRecord(new NUOC());
            cbbNuocSX.Properties.DisplayMember = "NuocID";
            cbbNuocSX.Properties.ValueMember = "NuocID";

            GGropDbOperation m_GGropDbOperation = new GGropDbOperation();
            cbbLoaiTB.Properties.DataSource = m_GGropDbOperation.GetRecord(new LOAITHIETBI());
            cbbLoaiTB.Properties.DisplayMember = "LoaiTBID";
            cbbLoaiTB.Properties.ValueMember = "LoaiTBID";

            ComponentDbOperation m_ComponentDbOperation = new ComponentDbOperation();
            cbbLinhKien.Properties.DataSource = m_ComponentDbOperation.GetRecord(new PHUTUNG());
            cbbLinhKien.Properties.DisplayMember = "TenPhuTung";
            cbbLinhKien.Properties.ValueMember = "PhuTungID";
        }

        private void btnAddLoaiTB_Click(object sender, EventArgs e)
        {
            frmGGroupDevice m_frmGGroupDevice = new frmGGroupDevice();
            m_frmGGroupDevice.Show();
        }

        private void btnAddNuocSX_Click(object sender, EventArgs e)
        {
            frmNuocSX m_frmNuocSX = new frmNuocSX();
            m_frmNuocSX.Show();
        }

        private void btnCreateLK_Click(object sender, EventArgs e)
        {
            frmComponents m_frmComponent = new frmComponents();
            m_frmComponent.Show();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnAddLinhKien_Click(object sender, EventArgs e)
        {

        }

        private void simpleButton1_Click(object sender, EventArgs e)
        {
            device = new THIETBI();
            device.MaThietBi = txtMaTB.Text;
            device.TenThietBi = txtTenTB.Text;
            device.SoHieu = txtSoHieuTB.Text;
            device.LoaiTBID = int.Parse(cbbLoaiTB.Text);
            device.DVTID = int.Parse(cbbDVT.Text);
            device.NuocSX = int.Parse(cbbNuocSX.Text);
            device.HanBaoHanh = short.Parse(cbbBaoHanh.Text);
            device.NamSX = int.Parse(cbbNamSX.Text);
            device.ThongSoKT = mmeTSKT.Text;
            device.MoTaThem = mmeMoTa.Text;
            device.TaiLieuKT = txtPath.Text;
            string message = devicebll.SaveRecordDevice(device);
            MessageBox.Show(message, "Message");
        }
    }
}